//
//  ViewController.m
//  手势
//
//  Created by 宋 on 15/12/21.
//  Copyright © 2015年 宋. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIGestureRecognizerDelegate>
{
    UIView *view;
    CGFloat ww;
    CGFloat xx;
    
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    view = [[UIView alloc] initWithFrame:CGRectMake(10, 200, 50, 50)];
    view.backgroundColor = [UIColor greenColor];
    [self.view addSubview:view];
   
    //移动
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onPan:)];
    [view addGestureRecognizer:pan];
    
    //缩放
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(onPinch:)];
    [view addGestureRecognizer:pinch];
    
    
    //旋转
    UIRotationGestureRecognizer * rota = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(onRota:)];
    [view addGestureRecognizer:rota];
    rota.delegate = self;
    //轻拍
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)];
    [view addGestureRecognizer:tap];
    
    //
    UILongPressGestureRecognizer *lpr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onlong:)];
    [view addGestureRecognizer:lpr];
    
    
}

- (void)onPan:(UIPanGestureRecognizer *)pan{
    CGPoint p = [pan translationInView:self.view];
//    CGRect rect = view.frame;
//    rect.origin.x += p.x;
//    rect.origin.y += p.y;
//    pan.view.frame = rect;
    pan.view.transform = CGAffineTransformTranslate(pan.view.transform, p.x, p.y);
    
    [pan setTranslation:CGPointZero inView:self.view];
}

- (void)onPinch:(UIPinchGestureRecognizer *)pinch{
    pinch.view.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
    
}

- (void)onRota:(UIRotationGestureRecognizer *)rota{
    rota.view.transform = CGAffineTransformMakeRotation(rota.rotation);
}

- (void)onTap:(UITapGestureRecognizer *)tap
{
    UIAlertController *aler = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"警告⚠️" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *act = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
        
    }];
    
    [aler addAction:act];
    [self presentViewController:aler animated:YES completion:nil];
    
//    UIAlertView *aler = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"是否退出" delegate:nil cancelButtonTitle:@"否" otherButtonTitles:@"是", nil];
//    [aler show];
    
}

- (void)onlong:(id)sender
{
    UIAlertView *aler = [[UIAlertView alloc] initWithTitle:@"提示" message:@"退出" delegate:nil cancelButtonTitle:@"否" otherButtonTitles:@"是", nil];
        [aler show];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
